package com.appkubes.mall.admin.application.supplier.supplier.controller;

import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.supplier.shop.service.SupplierShopService;
import com.appkubes.mall.admin.application.supplier.supplier.entity.vo.ApplySupplierVO;
import com.appkubes.mall.admin.application.supplier.supplier.entity.vo.ReleaseExamineGoodsVO;
import com.appkubes.mall.admin.application.supplier.supplier.entity.vo.SupplierKeyVO;
import com.appkubes.mall.core.controller.BaseMallSupplierController;
import com.appkubes.mall.core.entity.MallSupplier;
import com.appkubes.mall.core.entity.MallSupplierShop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Lin Jiaming
 * @Date: 2020/3/4 19:05
 * @Description:
 */
@Api(tags = "供应商模块")
@RequestMapping("/supplier")
@RestController
public class SupplierController extends BaseMallSupplierController {

    @Autowired
    SupplierShopService supplierShopService;


    @ApiOperation("申请商家")
    @PostMapping("/applySupplier")
    @Transactional
    public Response applySupplier(@ParamValid ApplySupplierVO applySupplierVO) {
        MallSupplier supplier = new MallSupplier();
        BeanUtils.copyProperties(applySupplierVO,supplier);
        MallSupplierShop supplierShop = new MallSupplierShop();
        BeanUtils.copyProperties(applySupplierVO,supplierShop);
        supplierShop.setStatus("PENDING");

        Boolean flag = this.baseService.save(supplier);

        supplierShop.setSupplierKey(supplier.getSupplierKey());
        supplierShopService.save(supplierShop);

        return Response.success(flag);
    }


    @ApiOperation("供应商信息")
    @GetMapping("/supplierInfo")
    public Response supplierInfo(@ParamValid SupplierKeyVO supplierKeyVO){
        return Response.success(this.getById(supplierKeyVO.getSupplierKey()));
    }
}
